package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.itheima.reggie.entity.AddressBook;
import com.itheima.reggie.mapper.AddressBookMapper;
import com.itheima.reggie.service.AddressBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressBookServiceImpl implements AddressBookService {
    @Autowired(required = false)
    private AddressBookMapper addressBookMapper;
    @Override
    public void save(AddressBook addressBook) {
     addressBookMapper.insert(addressBook);

    }

    @Override
    public void update(LambdaUpdateWrapper<AddressBook> wrapper) {
        addressBookMapper.update(null,wrapper);
    }

    @Override
    public void updateById(AddressBook addressBook) {
         addressBookMapper.updateById(addressBook);
    }

    @Override
    public AddressBook getById(Long id) {
        return addressBookMapper.selectById(id);
    }

    @Override
    public AddressBook getOne(LambdaQueryWrapper<AddressBook> queryWrapper) {
        return addressBookMapper.selectOne(queryWrapper);
    }

    @Override
    public List<AddressBook> list(LambdaQueryWrapper<AddressBook> queryWrapper) {
        return addressBookMapper.selectList(queryWrapper);
    }

    @Override
    public int deleteAddressBook(Long id) {
        int row = addressBookMapper.deleteById(id);
        return row;
    }
}
